﻿using NUnit.Framework;

namespace mebc.tests.parts
{
    [TestFixture]
    public class test_Part
    {
        [Test]
        public void Process_input()
        {
            var sut = new Handle_input();

            sut.InputPipe(new Message<int>{Value=42});
            sut.InputPipe(new Message<string>{Value="hello"});

            Assert.AreEqual(42, sut.d);
            Assert.AreEqual("hello", sut.t);
        }


        [Test]
        public void Produce_output()
        {
            var sut = new Send_output();

            int result = 0;
            sut.OutputPipe += _ => result = (int)_.Value;

            sut.PassOn(42);

            Assert.AreEqual(42, result);
        }
    }


    class Handle_input : Part
    {
        public int d;
        public string t;

        public Handle_input()
        {
            Process<int>(_ => d = _);
            Process<string>(StoreString);
        }

        private void StoreString(string t)
        {
            this.t = t;
        }
    }


    class Send_output : Part
    {
        public void PassOn(int d)
        {
            Send(d);
        }
    }
}
